<%--
  Created by IntelliJ IDEA.
  User: ENEN
  Date: 2023/12/28
  Time: 20:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="/resources/css/font.css">
    <link rel="stylesheet" href="/resources/css/xadmin.css">
    <script src="/resources/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/resources/js/xadmin.js"></script>
</head>

<body>
<div class="layui-fluid">
    <div class="layui-row">
    <!-- 编辑页面的表单 -->
    <form class="layui-form" lay-filter="editForm">
        <div class="layui-form-item">
            <label class="layui-form-label">ID：</label>
            <div class="layui-input-block">
                <input disabled type="text" name="id" lay-verify="required" autocomplete="off" placeholder="请输入姓名" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">部门名称：</label>
            <div class="layui-input-block">
                <input type="text" name="deptName" lay-verify="required" autocomplete="off" placeholder="请输入年龄" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">部门职责：</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" id="desc" name="deptJob" class="layui-textarea"></textarea>
            </div>
        </div>
        <!-- 其他表单项 -->
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="submitForm">提交</button>
            </div>
        </div>
    </form>
    </div>
</div>
<script>
    layui.use(['layer', 'form'], function(){
        var layer = layui.layer;
        var form = layui.form;

        // 从 sessionStorage 获取数据
        var editData = JSON.parse(sessionStorage.getItem('editData')) || {};

        // 在编辑页面中填充数据到表单
        form.val('editForm', {
            'id': editData.id,
            'deptName': editData.deptName,
            'deptJob': editData.deptJob
            // 可以根据实际情况添加其他字段
        });
    });
</script>
<script>
    layui.use(['form'], function(){
        var form = layui.form;

        // 监听提交按钮
        form.on('submit(submitForm)', function(data){
            // 获取表单数据
            // 这里可以将数据传递给其他地方，如发送到服务器等
            layer.msg(JSON.stringify(data.field));
            $.ajax({
                url:"/dept/deptEdit",
                type:"post",
                data:JSON.stringify(data.field),
                //告诉jquery，不要处理我的数据
                processData:false,
                //告诉jquery，不要设置我的content-type请求头
                contentType:"application/json",
                success:function (res){
                    if(res.code==200){
                        layer.msg(res.msg);
                        xadmin.close();
                        xadmin.father_reload();
                    }else{
                        layer.msg(res.msg);
                    }
                }
            })


            // 关闭当前页面
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);

            return false; // 阻止表单跳转
        });
    });
</script>
</body>

</html>
